package cn.tianyigps.tianyigpsm7clean.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 线程池配置
 * @author cui.guibin
 * @date 2018/5/28
 * @version 1.0
 * Description:
 */
@Configuration
public class ExecutorConfig {
    @Bean
    public Executor getExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置核心线程数
        executor.setCorePoolSize(100);
        // 设置最大线程数
        executor.setMaxPoolSize(Integer.MAX_VALUE);
        // 设置队列容量
        executor.setQueueCapacity(Integer.MAX_VALUE);
        // 设置线程活跃时间（秒）
        executor.setKeepAliveSeconds(20);
        //默认线程名字
        executor.setThreadNamePrefix("cleanThread-");
        //如果不初始化，导致找到不到执行器
        executor.initialize();
        return executor;
    }

}
